package org.example.utils;



import org.springframework.beans.factory.FactoryBean;

import java.util.Random;

/**
 * @program: maven3
 * @description:  水果工厂，这个类将由spring托管，它能生成各种水果
 * @author: zy
 * @create: 2025-09-09 11:13
 */
public class FruitFactoryBean implements FactoryBean<Fruit> {
    @Override
    public Fruit getObject() throws Exception {
        //根据不同的参数，生产不同的对象
        //根据条件来判断生产什么水果:      设计模式:简单工厂
        Random r=new Random();
        if( r.nextInt(   2) ==0){
            return new Apple();
        }
        return new Watermelon();
    }

    @Override
    public Class<?> getObjectType() {
        return Fruit.class;   //生产的产品的类型
    }

    @Override
    public boolean isSingleton() {
        return FactoryBean.super.isSingleton();
    }
}

